<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="产品名称" prop="pName">
      <el-input v-model="dataForm.pName" placeholder="产品名称"></el-input>
    </el-form-item>
    <el-form-item label="机构名称" prop="pMechanismname">
      <el-input v-model="dataForm.pMechanismname" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="产品类别" prop="pType">
      <el-input v-model="dataForm.pType" placeholder="产品类别"></el-input>
    </el-form-item>
    <el-form-item label="产品状态" prop="pStatues">
      <el-input v-model="dataForm.pStatues" placeholder="产品状态"></el-input>
    </el-form-item>
    <el-form-item label="使用状态" prop="pUsestatues">
      <el-input v-model="dataForm.pUsestatues" placeholder="使用状态"></el-input>
    </el-form-item>
    <el-form-item label="经办人" prop="pAgent">
      <el-input v-model="dataForm.pAgent" placeholder="经办人"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="pContacts">
      <el-input v-model="dataForm.pContacts" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="合同编号" prop="pContractid">
      <el-input v-model="dataForm.pContractid" placeholder="合同编号"></el-input>
    </el-form-item>
    <el-form-item label="选专区资源类型" prop="pSpecialtype">
      <el-input v-model="dataForm.pSpecialtype" placeholder="选专区资源类型"></el-input>
    </el-form-item>
    <el-form-item label="专区服务方式" prop="pSpecialserver">
      <el-input v-model="dataForm.pSpecialserver" placeholder="专区服务方式"></el-input>
    </el-form-item>
    <el-form-item label="专区开通账号数量" prop="pSpecialaccount">
      <el-input v-model="dataForm.pSpecialaccount" placeholder="专区开通账号数量"></el-input>
    </el-form-item>
    <el-form-item label="开通日期" prop="pSpecialdate">
      <el-input v-model="dataForm.pSpecialdate" placeholder="开通日期"></el-input>
    </el-form-item>
    <el-form-item label="IP段" prop="pSpecialip">
      <el-input v-model="dataForm.pSpecialip" placeholder="IP段"></el-input>
    </el-form-item>
    <el-form-item label="并发数" prop="pSpecialconcurent">
      <el-input v-model="dataForm.pSpecialconcurent" placeholder="并发数"></el-input>
    </el-form-item>
    <el-form-item label="前台用户名密码" prop="pBeforeuserandpsw">
      <el-input v-model="dataForm.pBeforeuserandpsw" placeholder="前台用户名密码"></el-input>
    </el-form-item>
    <el-form-item label="专区链接" prop="pSpeciallink">
      <el-input v-model="dataForm.pSpeciallink" placeholder="专区链接"></el-input>
    </el-form-item>
    <el-form-item label="后台链接" prop="pAfterlink">
      <el-input v-model="dataForm.pAfterlink" placeholder="后台链接"></el-input>
    </el-form-item>
    <el-form-item label="后台用户账号" prop="pAfteruserpsw">
      <el-input v-model="dataForm.pAfteruserpsw" placeholder="后台用户账号"></el-input>
    </el-form-item>
    <el-form-item label="通知状态" prop="pNoticestatues">
      <el-input v-model="dataForm.pNoticestatues" placeholder="通知状态"></el-input>
    </el-form-item>
    <el-form-item label="通知时间" prop="pNoticedate">
      <el-input v-model="dataForm.pNoticedate" placeholder="通知时间"></el-input>
    </el-form-item>
    <el-form-item label="通知地址" prop="pNoticeurl">
      <el-input v-model="dataForm.pNoticeurl" placeholder="通知地址"></el-input>
    </el-form-item>
    <el-form-item label="截图" prop="pCutpicture">
      <el-input v-model="dataForm.pCutpicture" placeholder="截图"></el-input>
    </el-form-item>
    <el-form-item label="产品质保期" prop="pPeriod">
      <el-input v-model="dataForm.pPeriod" placeholder="产品质保期"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="pSpecialremarks">
      <el-input v-model="dataForm.pSpecialremarks" placeholder="备注"></el-input>
    </el-form-item>
    <el-form-item label="app资源类型" prop="pApptype">
      <el-input v-model="dataForm.pApptype" placeholder="app资源类型"></el-input>
    </el-form-item>
    <el-form-item label="app服务方式" prop="pAppserver">
      <el-input v-model="dataForm.pAppserver" placeholder="app服务方式"></el-input>
    </el-form-item>
    <el-form-item label="app开通账号数" prop="pAppaccount">
      <el-input v-model="dataForm.pAppaccount" placeholder="app开通账号数"></el-input>
    </el-form-item>
    <el-form-item label="app备注" prop="pAppremarks">
      <el-input v-model="dataForm.pAppremarks" placeholder="app备注"></el-input>
    </el-form-item>
    <el-form-item label="微刊产品资源类型" prop="pWtype">
      <el-input v-model="dataForm.pWtype" placeholder="微刊产品资源类型"></el-input>
    </el-form-item>
    <el-form-item label="微刊服务方式" prop="pWserver">
      <el-input v-model="dataForm.pWserver" placeholder="微刊服务方式"></el-input>
    </el-form-item>
    <el-form-item label="微刊运营方式" prop="pWrunning">
      <el-input v-model="dataForm.pWrunning" placeholder="微刊运营方式"></el-input>
    </el-form-item>
    <el-form-item label="微刊账号" prop="pWaccount">
      <el-input v-model="dataForm.pWaccount" placeholder="微刊账号"></el-input>
    </el-form-item>
    <el-form-item label="微刊密码" prop="pWpsw">
      <el-input v-model="dataForm.pWpsw" placeholder="微刊密码"></el-input>
    </el-form-item>
    <el-form-item label="微刊地址" prop="pWurl">
      <el-input v-model="dataForm.pWurl" placeholder="微刊地址"></el-input>
    </el-form-item>
    <el-form-item label="微刊备注" prop="pRemarks">
      <el-input v-model="dataForm.pRemarks" placeholder="微刊备注"></el-input>
    </el-form-item>
    <el-form-item label="触屏产品看资源类型" prop="pTouchtype">
      <el-input v-model="dataForm.pTouchtype" placeholder="触屏产品看资源类型"></el-input>
    </el-form-item>
    <el-form-item label="触屏产品资源范围" prop="pTouchrange">
      <el-input v-model="dataForm.pTouchrange" placeholder="触屏产品资源范围"></el-input>
    </el-form-item>
    <el-form-item label="触屏数量" prop="pAccount">
      <el-input v-model="dataForm.pAccount" placeholder="触屏数量"></el-input>
    </el-form-item>
    <el-form-item label="触屏产品服务方式" prop="pTouchserver">
      <el-input v-model="dataForm.pTouchserver" placeholder="触屏产品服务方式"></el-input>
    </el-form-item>
    <el-form-item label="触屏产品备注" prop="pTouchremarks">
      <el-input v-model="dataForm.pTouchremarks" placeholder="触屏产品备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          pId: 0,
          pName: '',
          pMechanismname: '',
          pType: '',
          pStatues: '',
          pUsestatues: '',
          pAgent: '',
          pContacts: '',
          pContractid: '',
          pSpecialtype: '',
          pSpecialserver: '',
          pSpecialaccount: '',
          pSpecialdate: '',
          pSpecialip: '',
          pSpecialconcurent: '',
          pBeforeuserandpsw: '',
          pSpeciallink: '',
          pAfterlink: '',
          pAfteruserpsw: '',
          pNoticestatues: '',
          pNoticedate: '',
          pNoticeurl: '',
          pCutpicture: '',
          pPeriod: '',
          pSpecialremarks: '',
          pApptype: '',
          pAppserver: '',
          pAppaccount: '',
          pAppremarks: '',
          pWtype: '',
          pWserver: '',
          pWrunning: '',
          pWaccount: '',
          pWpsw: '',
          pWurl: '',
          pRemarks: '',
          pTouchtype: '',
          pTouchrange: '',
          pAccount: '',
          pTouchserver: '',
          pTouchremarks: ''
        },
        dataRule: {
          pName: [
            { required: true, message: '产品名称不能为空', trigger: 'blur' }
          ],
          pMechanismname: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          pType: [
            { required: true, message: '产品类别不能为空', trigger: 'blur' }
          ],
          pStatues: [
            { required: true, message: '产品状态不能为空', trigger: 'blur' }
          ],
          pUsestatues: [
            { required: true, message: '使用状态不能为空', trigger: 'blur' }
          ],
          pAgent: [
            { required: true, message: '经办人不能为空', trigger: 'blur' }
          ],
          pContacts: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          pContractid: [
            { required: true, message: '合同编号不能为空', trigger: 'blur' }
          ],
          pSpecialtype: [
            { required: true, message: '选专区资源类型不能为空', trigger: 'blur' }
          ],
          pSpecialserver: [
            { required: true, message: '专区服务方式不能为空', trigger: 'blur' }
          ],
          pSpecialaccount: [
            { required: true, message: '专区开通账号数量不能为空', trigger: 'blur' }
          ],
          pSpecialdate: [
            { required: true, message: '开通日期不能为空', trigger: 'blur' }
          ],
          pSpecialip: [
            { required: true, message: 'IP段不能为空', trigger: 'blur' }
          ],
          pSpecialconcurent: [
            { required: true, message: '并发数不能为空', trigger: 'blur' }
          ],
          pBeforeuserandpsw: [
            { required: true, message: '前台用户名密码不能为空', trigger: 'blur' }
          ],
          pSpeciallink: [
            { required: true, message: '专区链接不能为空', trigger: 'blur' }
          ],
          pAfterlink: [
            { required: true, message: '后台链接不能为空', trigger: 'blur' }
          ],
          pAfteruserpsw: [
            { required: true, message: '后台用户账号不能为空', trigger: 'blur' }
          ],
          pNoticestatues: [
            { required: true, message: '通知状态不能为空', trigger: 'blur' }
          ],
          pNoticedate: [
            { required: true, message: '通知时间不能为空', trigger: 'blur' }
          ],
          pNoticeurl: [
            { required: true, message: '通知地址不能为空', trigger: 'blur' }
          ],
          pCutpicture: [
            { required: true, message: '截图不能为空', trigger: 'blur' }
          ],
          pPeriod: [
            { required: true, message: '产品质保期不能为空', trigger: 'blur' }
          ],
          pSpecialremarks: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ],
          pApptype: [
            { required: true, message: 'app资源类型不能为空', trigger: 'blur' }
          ],
          pAppserver: [
            { required: true, message: 'app服务方式不能为空', trigger: 'blur' }
          ],
          pAppaccount: [
            { required: true, message: 'app开通账号数不能为空', trigger: 'blur' }
          ],
          pAppremarks: [
            { required: true, message: 'app备注不能为空', trigger: 'blur' }
          ],
          pWtype: [
            { required: true, message: '微刊产品资源类型不能为空', trigger: 'blur' }
          ],
          pWserver: [
            { required: true, message: '微刊服务方式不能为空', trigger: 'blur' }
          ],
          pWrunning: [
            { required: true, message: '微刊运营方式不能为空', trigger: 'blur' }
          ],
          pWaccount: [
            { required: true, message: '微刊账号不能为空', trigger: 'blur' }
          ],
          pWpsw: [
            { required: true, message: '微刊密码不能为空', trigger: 'blur' }
          ],
          pWurl: [
            { required: true, message: '微刊地址不能为空', trigger: 'blur' }
          ],
          pRemarks: [
            { required: true, message: '微刊备注不能为空', trigger: 'blur' }
          ],
          pTouchtype: [
            { required: true, message: '触屏产品看资源类型不能为空', trigger: 'blur' }
          ],
          pTouchrange: [
            { required: true, message: '触屏产品资源范围不能为空', trigger: 'blur' }
          ],
          pAccount: [
            { required: true, message: '触屏数量不能为空', trigger: 'blur' }
          ],
          pTouchserver: [
            { required: true, message: '触屏产品服务方式不能为空', trigger: 'blur' }
          ],
          pTouchremarks: [
            { required: true, message: '触屏产品备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.pId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.pId) {
            this.$http({
              url: this.$http.adornUrl(`/com/productinformation/info/${this.dataForm.pId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.pName = data.productInformation.pName
                this.dataForm.pMechanismname = data.productInformation.pMechanismname
                this.dataForm.pType = data.productInformation.pType
                this.dataForm.pStatues = data.productInformation.pStatues
                this.dataForm.pUsestatues = data.productInformation.pUsestatues
                this.dataForm.pAgent = data.productInformation.pAgent
                this.dataForm.pContacts = data.productInformation.pContacts
                this.dataForm.pContractid = data.productInformation.pContractid
                this.dataForm.pSpecialtype = data.productInformation.pSpecialtype
                this.dataForm.pSpecialserver = data.productInformation.pSpecialserver
                this.dataForm.pSpecialaccount = data.productInformation.pSpecialaccount
                this.dataForm.pSpecialdate = data.productInformation.pSpecialdate
                this.dataForm.pSpecialip = data.productInformation.pSpecialip
                this.dataForm.pSpecialconcurent = data.productInformation.pSpecialconcurent
                this.dataForm.pBeforeuserandpsw = data.productInformation.pBeforeuserandpsw
                this.dataForm.pSpeciallink = data.productInformation.pSpeciallink
                this.dataForm.pAfterlink = data.productInformation.pAfterlink
                this.dataForm.pAfteruserpsw = data.productInformation.pAfteruserpsw
                this.dataForm.pNoticestatues = data.productInformation.pNoticestatues
                this.dataForm.pNoticedate = data.productInformation.pNoticedate
                this.dataForm.pNoticeurl = data.productInformation.pNoticeurl
                this.dataForm.pCutpicture = data.productInformation.pCutpicture
                this.dataForm.pPeriod = data.productInformation.pPeriod
                this.dataForm.pSpecialremarks = data.productInformation.pSpecialremarks
                this.dataForm.pApptype = data.productInformation.pApptype
                this.dataForm.pAppserver = data.productInformation.pAppserver
                this.dataForm.pAppaccount = data.productInformation.pAppaccount
                this.dataForm.pAppremarks = data.productInformation.pAppremarks
                this.dataForm.pWtype = data.productInformation.pWtype
                this.dataForm.pWserver = data.productInformation.pWserver
                this.dataForm.pWrunning = data.productInformation.pWrunning
                this.dataForm.pWaccount = data.productInformation.pWaccount
                this.dataForm.pWpsw = data.productInformation.pWpsw
                this.dataForm.pWurl = data.productInformation.pWurl
                this.dataForm.pRemarks = data.productInformation.pRemarks
                this.dataForm.pTouchtype = data.productInformation.pTouchtype
                this.dataForm.pTouchrange = data.productInformation.pTouchrange
                this.dataForm.pAccount = data.productInformation.pAccount
                this.dataForm.pTouchserver = data.productInformation.pTouchserver
                this.dataForm.pTouchremarks = data.productInformation.pTouchremarks
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com/productinformation/${!this.dataForm.pId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'pId': this.dataForm.pId || undefined,
                'pName': this.dataForm.pName,
                'pMechanismname': this.dataForm.pMechanismname,
                'pType': this.dataForm.pType,
                'pStatues': this.dataForm.pStatues,
                'pUsestatues': this.dataForm.pUsestatues,
                'pAgent': this.dataForm.pAgent,
                'pContacts': this.dataForm.pContacts,
                'pContractid': this.dataForm.pContractid,
                'pSpecialtype': this.dataForm.pSpecialtype,
                'pSpecialserver': this.dataForm.pSpecialserver,
                'pSpecialaccount': this.dataForm.pSpecialaccount,
                'pSpecialdate': this.dataForm.pSpecialdate,
                'pSpecialip': this.dataForm.pSpecialip,
                'pSpecialconcurent': this.dataForm.pSpecialconcurent,
                'pBeforeuserandpsw': this.dataForm.pBeforeuserandpsw,
                'pSpeciallink': this.dataForm.pSpeciallink,
                'pAfterlink': this.dataForm.pAfterlink,
                'pAfteruserpsw': this.dataForm.pAfteruserpsw,
                'pNoticestatues': this.dataForm.pNoticestatues,
                'pNoticedate': this.dataForm.pNoticedate,
                'pNoticeurl': this.dataForm.pNoticeurl,
                'pCutpicture': this.dataForm.pCutpicture,
                'pPeriod': this.dataForm.pPeriod,
                'pSpecialremarks': this.dataForm.pSpecialremarks,
                'pApptype': this.dataForm.pApptype,
                'pAppserver': this.dataForm.pAppserver,
                'pAppaccount': this.dataForm.pAppaccount,
                'pAppremarks': this.dataForm.pAppremarks,
                'pWtype': this.dataForm.pWtype,
                'pWserver': this.dataForm.pWserver,
                'pWrunning': this.dataForm.pWrunning,
                'pWaccount': this.dataForm.pWaccount,
                'pWpsw': this.dataForm.pWpsw,
                'pWurl': this.dataForm.pWurl,
                'pRemarks': this.dataForm.pRemarks,
                'pTouchtype': this.dataForm.pTouchtype,
                'pTouchrange': this.dataForm.pTouchrange,
                'pAccount': this.dataForm.pAccount,
                'pTouchserver': this.dataForm.pTouchserver,
                'pTouchremarks': this.dataForm.pTouchremarks
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
